package cn.edu.ctbu.simplescoremanagementsystem.service.impl;

import cn.edu.ctbu.simplescoremanagementsystem.domain.Course;
import cn.edu.ctbu.simplescoremanagementsystem.repository.CourseRepository;
import cn.edu.ctbu.simplescoremanagementsystem.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    public CourseRepository courseRepository;

    public Course findByID(Integer id) {
        return courseRepository.findById(id).orElse(null);
    }

    public List<Course> findAll() {
        return courseRepository.findAll();
    }


    public Course insert(Course course) {
        courseRepository.save(course);
        return course;
    }

    public Course update(Course course) {
        courseRepository.save(course);
        return course;
    }

    public void deleteById(Integer id) {
        courseRepository.deleteById(id);
    }

    public Page<Course> getByPage(Pageable pageable) {
        return courseRepository.findAll(pageable);
    }

    public Page<Course> getByPage(Example<Course> course, Pageable pageable) {
        return courseRepository.findAll(course, pageable);
    }
}
